home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12157 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Correct usage of system call?
  5. Date: 29 Mar 1996 17:07:03 GMT
  6. Organization: OpenVision
  7. Message-ID: <4jh5bn$d56@spanky.pls.ov.com>
  8. References: <4jb03v$oi6@news.tamu.edu>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article oi6@news.tamu.edu, jrm4227@tam2000.tamu.edu (Justin Ray Mcelhanon) writes:
  13. >    Alright here is the situation I need help with, can not figure out the 
  14. >problem after at least three hours of trying to fix it.  I have written a small
  15. >c code that is a menu that calls up unix commands using sytems: 
  16. >
  17. >i.e)
  18. >   printf ("1. Pine");
  19. >   printf ("2. Usenet (tin)\n");
  20. >   printf ("3. Ftp\n");
  21. >
  22. >   scanf("%d", &choice);
  23. >    
  24. >  switch (choice)
  25. >     {
  26. >    case 1:
  27. >         printf ("Executing Pine\n");
  28. >         system("pine");
  29. >      break;     
  30. >
  31. >
  32. >It works great, however, I'd like to add in a command to allow one to 
  33. >type in the site name.  Example, when you call up the ftp case it does 
  34. >a scanf(%s,site); (with site declared as an char string) anyway I then 
  35. >want to take that and put it in the system command. ie system("ftp site"), 
  36. >but that is not the proper syntax, how could I accomplish this? That will
  37. >not work, I tested to see if the system command would even accept variables
  38. >as input, so I tried system(&site); ( BTW system(site) kept giving segmentation
  39. >faults) this code would properly send the output to unix shell, however, if
  40. >a space is place in the string it only reads the first part, and it also 
  41. >doesn't include ftp on the front.  What is the proper syntax to mix C
  42. >variables and unix system calls?  Mind you I've taught the little C and unix
  43. >I know from these news groups and such, so if something appears totally
  44. >wrong, it might be :)  If you'd like a better explination of the problem,
  45. >or want more of the code, email me at thorin@tamu.edu, and if you reply, 
  46. >please Carbon Copy me a response via mail because I don't trust the usenet
  47. >server, it plays Ollie North and cannot recall that post or reply.  Okay
  48. >thanks for the help
  49. >    
  50. >    
  51. >--
  52. >****************************************** A! JW2 WAR+++ PI++ BR+++ SL+++ SK+
  53. >Yakko: "Well it's been fun friend,         R&R++ GDF++ GP+++++ B&M++ HIP- SN+
  54. >but we've got to get back to               HN+++! MS+ ME+ CB~ MM++! KK-- CO++ 
  55. >planet reality now" (Baloney and Friends)  GLF-- P++ $++ E26 Ee10 TSlappy A18
  56. >Justin McElhanon----------thorin@tamu.edu   
  57. >******************************************
  58.  
  59.  
  60. The system command expects a single string for a command.  To do this
  61. with variable arguments requires that you create the string, and then
  62. pass the string into the system command.  For example:
  63.  
  64. char command[80];
  65. char *sitename;  /* assumed to point to desired site name */
  66.  
  67. sprintf(command, "ftp %s", sitename);
  68. system(command);
  69.  
  70.  
  71.             Fletcher.Glenn@ov.com
  72.  
  73.  
  74.